package com.yc.web.controller;

import com.yc.web.bean.TableDataGridResult;
import com.yc.web.bean.vo.DataVo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@RestController
public class DataController {
    List<DataVo> list=new ArrayList<>();
    {
        list.add(new DataVo("2","opop",0));
        list.add(new DataVo("3","opop",1));
        list.add(new DataVo("4","opop",1));
        list.add(new DataVo("5","opop",0));
        list.add(new DataVo("6","opop",0));
        list.add(new DataVo("7","opop",0));
        list.add(new DataVo("8","opop",0));
        list.add(new DataVo("9","opop",0));
        list.add(new DataVo("10","opop",0));
        list.add(new DataVo("11","opop",0));
        list.add(new DataVo("12","opop",0));
        list.add(new DataVo("14","opop",0));
        list.add(new DataVo("13","opop",0));
    }
    @RequestMapping("/ac/order.json")
    public TableDataGridResult<DataVo> get(){
        TableDataGridResult<DataVo> result=new TableDataGridResult<>();
        result.setRows(list);
        result.setTotal(list.size());
        return result;
    }
    @RequestMapping("/ac/update.json")
    public String update(DataVo vo){
        update(vo.getId(),vo.getOperate());
        return "sussces";
    }
    public List<DataVo> getList(){
        list.add(new DataVo("2","opop",0));
        list.add(new DataVo("3","opop",1));
        list.add(new DataVo("4","opop",1));
        list.add(new DataVo("5","opop",0));
        list.add(new DataVo("6","opop",0));
        list.add(new DataVo("7","opop",0));
        list.add(new DataVo("8","opop",0));
        list.add(new DataVo("9","opop",0));
        list.add(new DataVo("10","opop",0));
        list.add(new DataVo("11","opop",0));
        list.add(new DataVo("12","opop",0));
        list.add(new DataVo("14","opop",0));
        list.add(new DataVo("13","opop",0));
        return list;
    }
    public void update(String id,int status){
        list.stream().filter(a -> a.getId().equals(id)).forEach(a->a.setOperate(status));

        System.out.println(list);
    }
}
